package com.tgy.clickhouse.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.tgy.clickhouse.datasource.AIopsDynamicDatasource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class ClickHouseData {
    @Autowired
    private ClickHouseConfigProperties properties;

    @Bean(name = AIopsDynamicDatasource.CLICKHOUSE_DATASOURCE)
    @Qualifier(AIopsDynamicDatasource.CLICKHOUSE_DATASOURCE)
    public DataSource clickDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUsername(properties.getUserName());
        dataSource.setPassword(properties.getPassword());
        dataSource.setUrl(properties.getUrl());
        dataSource.setDriverClassName(properties.getDriverClassName());
        dataSource.setTestWhileIdle(properties.getTest_while_idle());
        dataSource.setValidationQuery(properties.getValidation_query());
        return dataSource;
    }
}
